home *** CD-ROM | disk | FTP | other *** search
- Path: linus.mitre.org!mbunix!jrv
- From: jrv@mbunix.mitre.org (Jim Van Zandt)
- Newsgroups: comp.lang.c
- Subject: Determining endianness - portable way?
- Date: 27 Feb 1996 18:35:11 GMT
- Organization: The MITRE Corporation
- Message-ID: <4gvisv$fc@linus.mitre.org>
- Reply-To: jrv@vanzandt.mv.com
- NNTP-Posting-Host: mbunix.mitre.org
-
-
- I have an application that writes short ints into a binary file, and
- want to make it portable to both little- and big-endian machines. I
- would like to use htons() (from BSD networking), but I find that
- Borland for one does not this in its library. Borland does provide
- bswap(), but how I do tell whether to call it? (Incidently, I was
- surprised to find that Stevens does not address this in his book
- Advanced Programming in the Unix Environment.)
-
- Is there a portable way to:
-
- - Put a short int into "network order"?
-
- - Discover the endianness of the intended architecture (e.g. standard
- #define)?
-
- - Determine the endianness of the current architecture
- (i.e. test program)?
-
- - Jim Van Zandt
-
- (email replies would be appreciated)
-